import moment from 'moment';
import { Random, mock } from 'mockjs';

// fake college ranking data
const colleges = {
  cy: '测绘学院',
  aq: '安全学院',
  ny: '能源学院',
  zh: '资环学院',
  jx: '机械学院',
  cl: '材料学院',
  dq: '电器学院',
  tm: '土木学院',
  jsj: '计算机学院',
  gs: '工商学院',
  cj: '财经学院',
  sx: '数信学院',
  mks: '马克思学院',
  wd: '物电学院',
  hg: '化工学院',
  wgy: '外国语学院',
  jy: '建艺学院',
  yj: '应急学院',
  wf: '文法学院',
  ty: '体育学院',
  yy: '音乐学院',
  y: '医学院',
  hbjg: '后备军官学院',
  jxjy: '继续教育学院',
};
const collegeData = Object.keys(colleges);

// mock data
const visitData = [];
const studentData = [];
const beginDay = new Date().getTime();

const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
for (let i = 0; i < fakeY.length; i += 1) {
  visitData.push({
    x: moment(new Date(`${2018 - i}-09-01`)).format('YYYY-MM-DD'),
    y: fakeY[i],
  });

  studentData.push({
    x: moment(new Date(`${2018 - i}-09-01`)).format('YYYY-MM-DD'),
    y: Random.natural(9500, 12000),
  });
}

const visitData2 = [];
const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
for (let i = 0; i < fakeY2.length; i += 1) {
  visitData2.push({
    x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format('YYYY-MM-DD'),
    y: fakeY2[i],
  });
}

const ascensionRate = []; // 升硕率
const attendanceRate = []; // 升硕率
for (let i = 0; i < 12; i += 1) {
  attendanceRate.push({
    x: `${i + 1}月`,
    y: Random.natural(120, 500),
  });

  ascensionRate.push({
    x: `${2018 - i}年`,
    y: Random.float(90, 97, 2, 2),
  });
}

const searchData = [];
for (let i = 0; i < 50; i += 1) {
  searchData.push({
    index: 2018 - i,
    keyword: Random.natural(10, 30),
    count: Random.natural(50, 60),
    range: Random.natural(10, 20),
    status: Random.natural(30, 50),
    totalManagement: Random.natural(30, 50),
    build: Random.natural(20, 40),
  });
}
const incomeData = [
  {
    x: '学杂费',
    y: 45444334,
  },
  {
    x: '推广教育',
    y: 332145,
  },
  {
    x: '建教合作',
    y: 31133256,
  },
  {
    x: '其他教学活动',
    y: 23412352,
  },
  {
    x: '补助及捐赠',
    y: 1231263,
  },
  {
    x: '财务收入',
    y: 1231254,
  },
  {
    x: '其他',
    y: 123123,
  },
];

const customOutcomeData = [
  {
    x: '行政管理',
    y: 2445325,
  },
  {
    x: '教学研究及训辅',
    y: 321324,
  },
  {
    x: '奖助学金',
    y: 311342,
  },
  {
    x: '推广教育及其他教学',
    y: 413422,
  },
  {
    x: '建教合作',
    y: 121354,
  },
  {
    x: '财务支出',
    y: 1112343,
  },
  {
    x: '其他',
    y: 111245,
  },
];

const capitalOutcomeData = [
  {
    x: '土地',
    y: 92453649,
  },
  {
    x: '土地改良物',
    y: 18845,
  },
  {
    x: '建筑物',
    y: 344264,
  },
  {
    x: '机械仪器及设备',
    y: 255235,
  },
  {
    x: '图书及博物',
    y: 6526456,
  },
  {
    x: '其他设备',
    y: 654887,
  },
  {
    x: '预付土地、工程及设备款',
    y: 652464,
  },
  {
    x: '租赁资产',
    y: 6523546,
  },
];

const offlineData = collegeData.map(key => ({
  name: colleges[key],
  cvr: Random.natural(95, 100) / 100,
}));

const offlineChartData = collegeData.map((key, index) => {
  const y1 = Random.natural(95, 100);
  return {
    x: new Date('2019-05-20').getTime() + 1000 * 60 * 60 * 24 * index,
    y1,
    y2: 100 - y1,
  };
});

const radarOriginData = [
  {
    name: '个人',
    ref: 10,
    koubei: 8,
    output: 4,
    contribute: 5,
    hot: 7,
  },
  {
    name: '团队',
    ref: 3,
    koubei: 9,
    output: 6,
    contribute: 3,
    hot: 1,
  },
  {
    name: '部门',
    ref: 4,
    koubei: 1,
    output: 6,
    contribute: 5,
    hot: 7,
  },
];

const radarData = [];
const radarTitleMap = {
  ref: '素质指标',
  koubei: '能力指标',
  output: '态度指标',
  contribute: '学生满意度指标',
  hot: '业绩指标',
};
radarOriginData.forEach(item => {
  Object.keys(item).forEach(key => {
    if (key !== 'name') {
      radarData.push({
        name: item.name,
        label: radarTitleMap[key],
        value: item[key],
      });
    }
  });
});

const collegeRankingAttendance = Random.shuffle(collegeData)
  .map((key, index) => ({
    title: colleges[key],
    total: index + 1,
  }))
  .slice(0, 10);

const collegeRankingEvaluation = Random.shuffle(collegeData)
  .map((key, index) => ({
    title: colleges[key],
    total: index + 1,
  }))
  .slice(0, 8);

const tags = mock({
  'list|100': [{ name: '@city', 'value|1-100': 150, 'type|0-2': 1 }],
}).list;

const getFakeChartData = {
  visitData,
  visitData2,
  searchData,
  radarData,
  offlineData,
  offlineChartData,

  // new
  studentData,
  collegeRankingAttendance,
  collegeRankingEvaluation,
  attendanceRate,
  ascensionRate,

  incomeData,
  customOutcomeData,
  capitalOutcomeData,
  tags,
};

export default {
  'GET /api/fake_chart_data': getFakeChartData,
};
